<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>【商城项目1】ubuntu安装docker mysql 和redis | Hexo</title><meta name="author" content="外星飞碟"><meta name="copyright" content="外星飞碟"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="【商城项目1】ubuntu安装docker mysql 和redis1.ubuntu16安装docker https:&#x2F;&#x2F;www.jianshu.com&#x2F;p&#x2F;bafa48ebd55e  2.dokcer启动1systemctl status docker  docker自动启动： 1sudo systemctl enable docker  3.docker配置镜像加速阿里云控制台，镜像中心，镜像">
<meta property="og:type" content="article">
<meta property="og:title" content="【商城项目1】ubuntu安装docker mysql 和redis">
<meta property="og:url" content="http://example.com/2020/09/10/%E3%80%90%E5%95%86%E5%9F%8E%E9%A1%B9%E7%9B%AE1%E3%80%91ubuntu%E5%AE%89%E8%A3%85docker%20mysql%20%E5%92%8Credis/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="【商城项目1】ubuntu安装docker mysql 和redis1.ubuntu16安装docker https:&#x2F;&#x2F;www.jianshu.com&#x2F;p&#x2F;bafa48ebd55e  2.dokcer启动1systemctl status docker  docker自动启动： 1sudo systemctl enable docker  3.docker配置镜像加速阿里云控制台，镜像中心，镜像">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://example.com/img/avatar.png">
<meta property="article:published_time" content="2020-09-10T15:03:07.000Z">
<meta property="article:modified_time" content="2020-09-08T03:32:45.579Z">
<meta property="article:author" content="外星飞碟">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/img/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2020/09/10/%E3%80%90%E5%95%86%E5%9F%8E%E9%A1%B9%E7%9B%AE1%E3%80%91ubuntu%E5%AE%89%E8%A3%85docker%20mysql%20%E5%92%8Credis/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/',
  hexoversion: '5.1.1',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  baiduPush: false,
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isSidebar: true,
  postUpdate: '2020-09-08 11:32:45'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>var activateDarkMode = function () {
  document.documentElement.setAttribute('data-theme', 'dark')
  if (document.querySelector('meta[name="theme-color"]') !== null) {
    document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
  }
}
var activateLightMode = function () {
  document.documentElement.setAttribute('data-theme', 'light')
  if (document.querySelector('meta[name="theme-color"]') !== null) {
    document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
  }
}

var autoChangeMode = 'false'
var t = saveToLocal.get('theme')
if (autoChangeMode === '1') {
  var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
  var isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
  var isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
  var hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

  if (t === undefined) {
    if (isLightMode) activateLightMode()
    else if (isDarkMode) activateDarkMode()
    else if (isNotSpecified || hasNoSupport) {
      var now = new Date()
      var hour = now.getHours()
      var isNight = hour <= 6 || hour >= 18
      isNight ? activateDarkMode() : activateLightMode()
    }
    window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
      if (saveToLocal.get('theme') === undefined) {
        e.matches ? activateDarkMode() : activateLightMode()
      }
    })
  } else if (t === 'light') activateLightMode()
  else activateDarkMode()
} else if (autoChangeMode === '2') {
  now = new Date()
  hour = now.getHours()
  isNight = hour <= 6 || hour >= 18
  if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
  else if (t === 'light') activateLightMode()
  else activateDarkMode()
} else {
  if (t === 'dark') activateDarkMode()
  else if (t === 'light') activateLightMode()
}</script><meta name="generator" content="Hexo 5.1.1"><link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
</head><body><div id="mobile-sidebar"><div id="menu_mask"></div><div id="mobile-sidebar-menus"><div class="mobile_author_icon"><img class="avatar-img" src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="mobile_post_data"><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/archives/"><div class="headline">Articles</div><div class="length_num">6</div></a></div></div></div><hr/></div></div><div id="body-wrap"><div id="sidebar"><i class="fas fa-arrow-right on" id="toggle-sidebar"></i><div class="sidebar-toc"><div class="sidebar-toc__title">Catalog</div><div class="sidebar-toc__progress"><span class="progress-notice">You've read</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar">     </div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E3%80%90%E5%95%86%E5%9F%8E%E9%A1%B9%E7%9B%AE1%E3%80%91ubuntu%E5%AE%89%E8%A3%85docker-mysql-%E5%92%8Credis"><span class="toc-number">1.</span> <span class="toc-text">【商城项目1】ubuntu安装docker mysql 和redis</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-ubuntu16%E5%AE%89%E8%A3%85docker"><span class="toc-number">2.</span> <span class="toc-text">1.ubuntu16安装docker</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-dokcer%E5%90%AF%E5%8A%A8"><span class="toc-number">3.</span> <span class="toc-text">2.dokcer启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-docker%E9%85%8D%E7%BD%AE%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F"><span class="toc-number">4.</span> <span class="toc-text">3.docker配置镜像加速</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%88%9B%E5%BB%BAmysql%E5%AE%9E%E4%BE%8B"><span class="toc-number">5.</span> <span class="toc-text">4.创建mysql实例</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%88%A0%E9%99%A4%E4%B8%80%E4%B8%AA%E5%AE%9E%E4%BE%8B"><span class="toc-number">6.</span> <span class="toc-text">5.删除一个实例</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E5%81%9C%E6%AD%A2%E5%92%8C%E5%90%AF%E5%8A%A8%E4%B8%80%E4%B8%AA%E5%AE%9E%E4%BE%8B"><span class="toc-number">7.</span> <span class="toc-text">6. 停止和启动一个实例</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E5%88%9B%E5%BB%BAredis%E5%AE%9E%E4%BE%8B"><span class="toc-number">8.</span> <span class="toc-text">7.创建redis实例</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E9%80%9A%E8%BF%87navicat%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5mysql"><span class="toc-number">9.</span> <span class="toc-text">8.通过navicat远程连接mysql</span></a></li></ol></div></div></div><header class="post-bg" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Hexo</a></span><span id="menus"><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><div id="post-title"><div class="posttitle">【商城项目1】ubuntu安装docker mysql 和redis</div></div><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2020-09-10T15:03:07.000Z" title="Created 2020-09-10 23:03:07">2020-09-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2020-09-08T03:32:45.579Z" title="Updated 2020-09-08 11:32:45">2020-09-08</time></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout_post" id="content-inner"><article id="post"><div class="post-content" id="article-container"><h2 id="【商城项目1】ubuntu安装docker-mysql-和redis"><a href="#【商城项目1】ubuntu安装docker-mysql-和redis" class="headerlink" title="【商城项目1】ubuntu安装docker mysql 和redis"></a>【商城项目1】ubuntu安装docker mysql 和redis</h2><h2 id="1-ubuntu16安装docker"><a href="#1-ubuntu16安装docker" class="headerlink" title="1.ubuntu16安装docker"></a>1.ubuntu16安装docker</h2><p> <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/bafa48ebd55e">https://www.jianshu.com/p/bafa48ebd55e</a> </p>
<h2 id="2-dokcer启动"><a href="#2-dokcer启动" class="headerlink" title="2.dokcer启动"></a>2.dokcer启动</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl status docker</span><br></pre></td></tr></table></figure>

<p>docker自动启动：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl enable docker</span><br></pre></td></tr></table></figure>

<h2 id="3-docker配置镜像加速"><a href="#3-docker配置镜像加速" class="headerlink" title="3.docker配置镜像加速"></a>3.docker配置镜像加速</h2><p>阿里云控制台，镜像中心，镜像加速器，参照里面的文档配置加速~</p>
<h2 id="4-创建mysql实例"><a href="#4-创建mysql实例" class="headerlink" title="4.创建mysql实例"></a>4.创建mysql实例</h2><p>下载mysql：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo docker pull mysql</span><br></pre></td></tr></table></figure>

<p>查看镜像列表：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo docker images  </span><br></pre></td></tr></table></figure>

<p>创建并运行一个mysql实例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 3306:3306 --name mymysql -v $PWD&#x2F;conf:&#x2F;etc&#x2F;mysql&#x2F;conf.d -v $PWD&#x2F;logs:&#x2F;logs -v $PWD&#x2F;data:&#x2F;var&#x2F;lib&#x2F;mysql -e MYSQL_ROOT_PASSWORD&#x3D;123456 -d mysql</span><br></pre></td></tr></table></figure>

<h2 id="5-删除一个实例"><a href="#5-删除一个实例" class="headerlink" title="5.删除一个实例"></a>5.删除一个实例</h2><p>如果想删除实例：</p>
<p>先查看实例列表：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps -a</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rm 实例名称</span><br></pre></td></tr></table></figure>

<h2 id="6-停止和启动一个实例"><a href="#6-停止和启动一个实例" class="headerlink" title="6. 停止和启动一个实例"></a>6. 停止和启动一个实例</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker stop 实例名称</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start 实例名称</span><br></pre></td></tr></table></figure>

<h2 id="7-创建redis实例"><a href="#7-创建redis实例" class="headerlink" title="7.创建redis实例"></a>7.创建redis实例</h2><p>下载redis：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo docker pull redis</span><br></pre></td></tr></table></figure>

<p>创建redis实例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 6379:6379 --name redis \</span><br><span class="line">-v $PWD&#x2F;mydata&#x2F;redis&#x2F;data:&#x2F;data \</span><br><span class="line">-v $PWD&#x2F;mydata&#x2F;redis&#x2F;conf&#x2F;redis.conf:&#x2F;etc&#x2F;redis&#x2F;redis.conf \</span><br><span class="line">-d redis redis-server &#x2F;etc&#x2F;redis&#x2F;redis.conf</span><br></pre></td></tr></table></figure>

<p>———–2020.05.22———</p>
<h2 id="8-通过navicat远程连接mysql"><a href="#8-通过navicat远程连接mysql" class="headerlink" title="8.通过navicat远程连接mysql"></a>8.通过navicat远程连接mysql</h2><p>每次开机都要先启动mysql：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start mymysql</span><br></pre></td></tr></table></figure>

<p><img src="https://gitee.com/ufo360/typora/raw/master/image-20200523211354007.png" alt="image-20200523211354007"></p>
<p>redis也一样~~</p>
<p>然后navicat建立连接：</p>
<p><img src="https://gitee.com/ufo360/typora/raw/master/image-20200523211425212.png" alt="image-20200523211425212"></p>
<p><img src="https://gitee.com/ufo360/typora/raw/master/image-20200523211449680.png" alt="image-20200523211449680"></p>
<p>连接成功~</p>
</div><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="mailto:undefined">ufo</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://example.com/2020/09/10/%E3%80%90%E5%95%86%E5%9F%8E%E9%A1%B9%E7%9B%AE1%E3%80%91ubuntu%E5%AE%89%E8%A3%85docker%20mysql%20%E5%92%8Credis/">http://example.com/2020/09/10/%E3%80%90%E5%95%86%E5%9F%8E%E9%A1%B9%E7%9B%AE1%E3%80%91ubuntu%E5%AE%89%E8%A3%85docker%20mysql%20%E5%92%8Credis/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/avatar.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/09/10/maven%E6%90%AD%E5%BB%BAspringboot+thymeleaf/"><img class="prev-cover" src="/null" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">maven搭建springboot+thymeleaf</div></div></a></div><div class="next-post pull-right"><a href="/2020/09/10/%E3%80%90%E5%95%86%E5%9F%8E%E9%A1%B9%E7%9B%AE2%E3%80%91%E9%85%8D%E7%BD%AEgit/"><img class="next-cover" src="/null" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">【商城项目2】配置git</div></div></a></div></nav></article></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 By 外星飞碟</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><section id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></section><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></div></body></html>